var fbplugin={};
fbplugin.uid=0;
fbplugin.accessToken=0;
fbplugin.saveUserDataUrl='';
fbplugin.getPermission=function(permission,action){	
	//window.location=url;
	FB.login(function(response) {
	   // handle the response
	   if (response.authResponse) {
		   fbplugin.accessToken=response.authResponse.accessToken;
		   fbplugin.uid=response.authResponse.userID;
		   //saveuser
		   fbplugin.saveUserData();
		   //do action
		   if(action!=undefined || action!=null){
			   eval(action);			   
		   }		   
		}	   
	 }, {scope: permission});
}
fbplugin.saveUserData=function(){
	FB.api(
	        'https://graph.facebook.com/'+this.uid,	        
	        function(response) {
	           if (!response || response.error) {
	              //printObject(response.error);
	           } else {
	        	   //printObject(response);				   
	        	   $.ajax({
	        		   type: "POST",
	        		   url: fbplugin.saveUserDataUrl,
	        		   data: { data: response },
	        		   dataType: "jsonp"
	        		 });
	              //alert('Cook was successful! Action ID: ' + response.id);
	           }
	        });
	
}
fbplugin.readit=function(){
	FB.api(
	        'https://graph.facebook.com/me/news.reads?article='+this.selfurl,
	        'post',
	        function(response) {
	           if (!response || response.error) {
	              //printObject(response.error);
	           } else {
	              //alert('Cook was successful! Action ID: ' + response.id);
	           }
	        });
		
}

fbplugin.join=function(action,failaction){	
		
	FB.api(
        '/me/scyclub:join?activity='+this.selfurl,
        'post',
        function(response) {
           if (!response || response.error) {              
        	  //printObject(response.error);
			  eval(failaction);
           } else {
        	 //show join
       		eval(action);
              //alert('Cook was successful! Action ID: ' + response.id);
           }
        });
	
}